package com.corticon.client.validation;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;

import com.corticon.client.model.DialogRequestInput;

public class DialogRequestValidator extends GenericHibernateValidator<DialogRequestInput> {
	public DialogRequestValidator(ValidationMessageFormatter validationMessageFormatter) {
		super.validationMessageFormatter = validationMessageFormatter;
	}

	@Override
	protected void complexValidate(Object object, Errors errors) {
		super.complexValidate(object, errors);
		DialogRequestInput validator = (DialogRequestInput) object;
		if (StringUtils.isEmpty(validator.getMode())==false) {
			if (!validator.getMode().equals("explicit") && !validator.getMode().equals("implicit")){
				errors.rejectValue("mode", "dialogRequest.validate.mode.otherChar", "default message");
			}
			if (validator.getMode().equals("explicit") && (validator.getDialogInstanceId()==null || validator.getDialogInstanceId().equals("0"))){
				errors.rejectValue("dialogInstanceId", "dialogReqeust.validate.dialogInstanceId.notEmpty", "default message");
			}			
		}
		List<Character> vocabularyExcludedChars = new ArrayList<Character>();
		vocabularyExcludedChars.add('_');
		String[] nameArgs = { "dialogInstanceId" };
		commonCharactersValidate(validator.getDialogInstanceId(), vocabularyExcludedChars, errors, "dialogInstanceId", "E00001", nameArgs, "default message");
		String[] nameArgs1 = { "sessionId" };
		commonCharactersValidate(validator.getSessionId(), vocabularyExcludedChars, errors, "sessionId", "E00001", nameArgs1, "default message");
		String[] nameArgs2 = { "mode" };
		commonCharactersValidate(validator.getMode(), vocabularyExcludedChars, errors, "mode", "E00001", nameArgs2, "default message");
		String[] nameArgs3 = { "effDate" };
		commonCharactersValidate(validator.getEffDate(), vocabularyExcludedChars, errors, "effDate", "E00001", nameArgs3, "default message");
		String[] nameArgs4 = { "functions" };
		commonCharactersValidate(validator.getFunctions(), vocabularyExcludedChars, errors, "functions", "E00001", nameArgs4, "default message");
		String[] nameArgs5 = { "locale" };
		commonCharactersValidate(validator.getLocale(), vocabularyExcludedChars, errors, "locale", "E00001", nameArgs5, "default message");
		String[] nameArgs6 = { "product" };
		commonCharactersValidate(validator.getProduct(), vocabularyExcludedChars, errors, "product", "E00001", nameArgs6, "default message");
		String[] nameArgs7 = { "region" };
		commonCharactersValidate(validator.getRegion(), vocabularyExcludedChars, errors, "region", "E00001", nameArgs7, "default message");
		String[] nameArgs8 = { "status" };
		commonCharactersValidate(validator.getStatus(), vocabularyExcludedChars, errors, "status", "E00001", nameArgs8, "default message");
	}

}
